package com.cmii.sjw.department.control.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * 钉钉请求状态码枚举
 *
 * @author <a href="mailto:tanghaotian@alu.uestc.edu.cn" rel="nofollow">cddysq</a>
 * @version 1.0.0
 * @date 2024/6/12 10:09
 * @since 1.0.0
 **/
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum DingTalkRequestStatusCodeEnum {

    /**
     * authCode失效或不存在
     */
    AUTH_CODE_INVALID_OR_NOT_EXIST("240132", "authCode失效或不存在"),

    /**
     * 应用accessToken失效或不存在
     */
    ACCESS_TOKEN_INVALID_OR_NOT_EXIST("240133", "应用accessToken失效或不存在"),
    /**
     * 未知状态码
     */
    UNKNOWN("", "未知状态码");

    /**
     * 根据钉钉请求状态码查询定义枚举
     *
     * @param code 请求状态码
     * @return {@link DingTalkRequestStatusCodeEnum}
     */
    public static DingTalkRequestStatusCodeEnum findEnumByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return UNKNOWN;
        }
        for (DingTalkRequestStatusCodeEnum dingTalkRequestStatusCodeEnum : DingTalkRequestStatusCodeEnum.values()) {
            if (dingTalkRequestStatusCodeEnum.getCode().equals(code)) {
                return dingTalkRequestStatusCodeEnum;
            }
        }
        return null;
    }

    /**
     * 编码
     */
    private final String code;

    /**
     * 描述
     */
    private final String description;
}
